/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package com.unwiredgrain.modeling.sscm.impl;

import com.unwiredgrain.modeling.sscm.Classifier;
import com.unwiredgrain.modeling.sscm.Interface;
import com.unwiredgrain.modeling.sscm.Module;
import com.unwiredgrain.modeling.sscm.Protocol;
import com.unwiredgrain.modeling.sscm.SSCMPackage;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Package</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link com.unwiredgrain.modeling.sscm.impl.PackageImpl#getSuperPackage <em>Super Package</em>}</li>
 *   <li>{@link com.unwiredgrain.modeling.sscm.impl.PackageImpl#getSubPackages <em>Sub Packages</em>}</li>
 *   <li>{@link com.unwiredgrain.modeling.sscm.impl.PackageImpl#getClassifiers <em>Classifiers</em>}</li>
 *   <li>{@link com.unwiredgrain.modeling.sscm.impl.PackageImpl#getProtocols <em>Protocols</em>}</li>
 *   <li>{@link com.unwiredgrain.modeling.sscm.impl.PackageImpl#getFacades <em>Facades</em>}</li>
 *   <li>{@link com.unwiredgrain.modeling.sscm.impl.PackageImpl#getModules <em>Modules</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class PackageImpl extends NamedElementImpl implements com.unwiredgrain.modeling.sscm.Package {
	/**
	 * The cached value of the '{@link #getSubPackages() <em>Sub Packages</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSubPackages()
	 * @generated
	 * @ordered
	 */
	protected EList<com.unwiredgrain.modeling.sscm.Package> subPackages;

	/**
	 * The cached value of the '{@link #getClassifiers() <em>Classifiers</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getClassifiers()
	 * @generated
	 * @ordered
	 */
	protected EList<Classifier> classifiers;

	/**
	 * The cached value of the '{@link #getProtocols() <em>Protocols</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getProtocols()
	 * @generated
	 * @ordered
	 */
	protected EList<Protocol> protocols;

	/**
	 * The cached value of the '{@link #getFacades() <em>Facades</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getFacades()
	 * @generated
	 * @ordered
	 */
	protected EList<Interface> facades;

	/**
	 * The cached value of the '{@link #getModules() <em>Modules</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getModules()
	 * @generated
	 * @ordered
	 */
	protected EList<Module> modules;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected PackageImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return SSCMPackage.Literals.PACKAGE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Classifier> getClassifiers() {
		if (classifiers == null) {
			classifiers = new EObjectContainmentEList<Classifier>(Classifier.class, this, SSCMPackage.PACKAGE__CLASSIFIERS);
		}
		return classifiers;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Protocol> getProtocols() {
		if (protocols == null) {
			protocols = new EObjectContainmentEList<Protocol>(Protocol.class, this, SSCMPackage.PACKAGE__PROTOCOLS);
		}
		return protocols;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Interface> getFacades() {
		if (facades == null) {
			facades = new EObjectContainmentEList<Interface>(Interface.class, this, SSCMPackage.PACKAGE__FACADES);
		}
		return facades;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Module> getModules() {
		if (modules == null) {
			modules = new EObjectContainmentEList<Module>(Module.class, this, SSCMPackage.PACKAGE__MODULES);
		}
		return modules;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public com.unwiredgrain.modeling.sscm.Package getSuperPackage() {
		if (eContainerFeatureID() != SSCMPackage.PACKAGE__SUPER_PACKAGE) return null;
		return (com.unwiredgrain.modeling.sscm.Package)eContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetSuperPackage(com.unwiredgrain.modeling.sscm.Package newSuperPackage, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newSuperPackage, SSCMPackage.PACKAGE__SUPER_PACKAGE, msgs);
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setSuperPackage(com.unwiredgrain.modeling.sscm.Package newSuperPackage) {
		if (newSuperPackage != eInternalContainer() || (eContainerFeatureID() != SSCMPackage.PACKAGE__SUPER_PACKAGE && newSuperPackage != null)) {
			if (EcoreUtil.isAncestor(this, newSuperPackage))
				throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newSuperPackage != null)
				msgs = ((InternalEObject)newSuperPackage).eInverseAdd(this, SSCMPackage.PACKAGE__SUB_PACKAGES, com.unwiredgrain.modeling.sscm.Package.class, msgs);
			msgs = basicSetSuperPackage(newSuperPackage, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SSCMPackage.PACKAGE__SUPER_PACKAGE, newSuperPackage, newSuperPackage));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<com.unwiredgrain.modeling.sscm.Package> getSubPackages() {
		if (subPackages == null) {
			subPackages = new EObjectContainmentWithInverseEList<com.unwiredgrain.modeling.sscm.Package>(com.unwiredgrain.modeling.sscm.Package.class, this, SSCMPackage.PACKAGE__SUB_PACKAGES, SSCMPackage.PACKAGE__SUPER_PACKAGE);
		}
		return subPackages;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case SSCMPackage.PACKAGE__SUPER_PACKAGE:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetSuperPackage((com.unwiredgrain.modeling.sscm.Package)otherEnd, msgs);
			case SSCMPackage.PACKAGE__SUB_PACKAGES:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getSubPackages()).basicAdd(otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case SSCMPackage.PACKAGE__SUPER_PACKAGE:
				return basicSetSuperPackage(null, msgs);
			case SSCMPackage.PACKAGE__SUB_PACKAGES:
				return ((InternalEList<?>)getSubPackages()).basicRemove(otherEnd, msgs);
			case SSCMPackage.PACKAGE__CLASSIFIERS:
				return ((InternalEList<?>)getClassifiers()).basicRemove(otherEnd, msgs);
			case SSCMPackage.PACKAGE__PROTOCOLS:
				return ((InternalEList<?>)getProtocols()).basicRemove(otherEnd, msgs);
			case SSCMPackage.PACKAGE__FACADES:
				return ((InternalEList<?>)getFacades()).basicRemove(otherEnd, msgs);
			case SSCMPackage.PACKAGE__MODULES:
				return ((InternalEList<?>)getModules()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
		switch (eContainerFeatureID()) {
			case SSCMPackage.PACKAGE__SUPER_PACKAGE:
				return eInternalContainer().eInverseRemove(this, SSCMPackage.PACKAGE__SUB_PACKAGES, com.unwiredgrain.modeling.sscm.Package.class, msgs);
		}
		return super.eBasicRemoveFromContainerFeature(msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case SSCMPackage.PACKAGE__SUPER_PACKAGE:
				return getSuperPackage();
			case SSCMPackage.PACKAGE__SUB_PACKAGES:
				return getSubPackages();
			case SSCMPackage.PACKAGE__CLASSIFIERS:
				return getClassifiers();
			case SSCMPackage.PACKAGE__PROTOCOLS:
				return getProtocols();
			case SSCMPackage.PACKAGE__FACADES:
				return getFacades();
			case SSCMPackage.PACKAGE__MODULES:
				return getModules();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case SSCMPackage.PACKAGE__SUPER_PACKAGE:
				setSuperPackage((com.unwiredgrain.modeling.sscm.Package)newValue);
				return;
			case SSCMPackage.PACKAGE__SUB_PACKAGES:
				getSubPackages().clear();
				getSubPackages().addAll((Collection<? extends com.unwiredgrain.modeling.sscm.Package>)newValue);
				return;
			case SSCMPackage.PACKAGE__CLASSIFIERS:
				getClassifiers().clear();
				getClassifiers().addAll((Collection<? extends Classifier>)newValue);
				return;
			case SSCMPackage.PACKAGE__PROTOCOLS:
				getProtocols().clear();
				getProtocols().addAll((Collection<? extends Protocol>)newValue);
				return;
			case SSCMPackage.PACKAGE__FACADES:
				getFacades().clear();
				getFacades().addAll((Collection<? extends Interface>)newValue);
				return;
			case SSCMPackage.PACKAGE__MODULES:
				getModules().clear();
				getModules().addAll((Collection<? extends Module>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case SSCMPackage.PACKAGE__SUPER_PACKAGE:
				setSuperPackage((com.unwiredgrain.modeling.sscm.Package)null);
				return;
			case SSCMPackage.PACKAGE__SUB_PACKAGES:
				getSubPackages().clear();
				return;
			case SSCMPackage.PACKAGE__CLASSIFIERS:
				getClassifiers().clear();
				return;
			case SSCMPackage.PACKAGE__PROTOCOLS:
				getProtocols().clear();
				return;
			case SSCMPackage.PACKAGE__FACADES:
				getFacades().clear();
				return;
			case SSCMPackage.PACKAGE__MODULES:
				getModules().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case SSCMPackage.PACKAGE__SUPER_PACKAGE:
				return getSuperPackage() != null;
			case SSCMPackage.PACKAGE__SUB_PACKAGES:
				return subPackages != null && !subPackages.isEmpty();
			case SSCMPackage.PACKAGE__CLASSIFIERS:
				return classifiers != null && !classifiers.isEmpty();
			case SSCMPackage.PACKAGE__PROTOCOLS:
				return protocols != null && !protocols.isEmpty();
			case SSCMPackage.PACKAGE__FACADES:
				return facades != null && !facades.isEmpty();
			case SSCMPackage.PACKAGE__MODULES:
				return modules != null && !modules.isEmpty();
		}
		return super.eIsSet(featureID);
	}

} //PackageImpl
